package com.cnc.tag;

import com.cnc.bas.util.StringUtil;
import com.cnc.ssm.ISsmService;

import org.apache.struts.util.RequestUtils;
import org.apache.struts.util.ResponseUtils;

import javax.servlet.jsp.JspException;

/**
 * @author �ű���  ������ͨϵͳ�������޹�˾
 * @version 1.1.0
 */
public class Code2NameTag extends LtcmTag {

    private String name;
    private String property;
    private String returnField;
    private String codeType;
    private String styleId;
    private String styleClass;
    private String value;
    private String readonly;
    private String disabled;
    private boolean idNumber = false;

    public boolean isIdNumber() {
        return idNumber;
    }

    public void setIdNumber(boolean idNumber) {
        this.idNumber = idNumber;
    }

    public String getCodeType() {
        return codeType;
    }

    public void setCodeType(String codeType) {
        this.codeType = codeType;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getProperty() {
        return property;
    }

    public void setProperty(String property) {
        this.property = property;
    }

    public String getStyleId() {
        return styleId;
    }

    public void setStyleId(String styleId) {
        this.styleId = styleId;
    }

    public String getStyleClass() {
        return styleClass;
    }

    public void setStyleClass(String styleClass) {
        this.styleClass = styleClass;
    }

    public String getValue() {
        return value;
    }

    public void setValue(String value) {
        this.value = value;
    }

    public String getReturnField() {
        return returnField;
    }

    public void setReturnField(String returnField) {
        this.returnField = returnField;
    }

    public String getReadonly() {
        return readonly;
    }

    public void setReadonly(String readonly) {
        this.readonly = readonly;
    }

    public String getDisabled() {
        return disabled;
    }

    public void setDisabled(String disabled) {
        this.disabled = disabled;
    }

    public int doEndTag() throws JspException {
        ISsmService ssmService = (ISsmService) this.getBean(com.cnc.bas.util.Constants.BEAN_NAME_SSM);
        String codeValue = value;
        if (value == null) {
            Object oValue = RequestUtils.lookup(pageContext, name, property, null);
            if (oValue != null) codeValue = oValue.toString();
        }
        codeValue = ResponseUtils.filter(codeValue);
        String name = "";
        if (!StringUtil.null2Empty(codeValue).equals(""))
            name = ssmService.getNameByCode(this.codeType, codeValue);
        StringBuffer results = new StringBuffer();
        results.append("<input type='text' ");
        if (this.property != null) results.append(" name='_" + this.property + "'");
        if (this.styleClass != null) results.append(" class='" + this.styleClass + "'");
        if (this.styleId != null) results.append(" style='" + this.styleId + "'");
        if (this.readonly != null && this.readonly.equalsIgnoreCase("true"))
            results.append(" readonly ");
        if (this.disabled != null && this.disabled.equalsIgnoreCase("true"))
            results.append(" disabled ");
        results.append(" value=\"" + (StringUtil.null2Empty(name)).trim() + "\" > ");
        ResponseUtils.write(pageContext, results.toString());
        return (EVAL_PAGE);
    }

}
